package com.fantastic.web.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @author: rxx
 * @since: 2024/6/13 15:42
 * @description: caffeine缓存配置类
 */
@Configuration
public class CacheConfig {
    /**
     * 交由spring容器管理
     *
     * @return
     */
    @Bean
    public Cache<Object, Object> caffeineCache() {
        //指定缓存项的过期时间为 30 秒。
        return Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(300)).build();
    }
}
